#pragma once
#ifndef ParameterReader_HPP_
#define ParameterReader_HPP_

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include "Types.hpp"
#include "Utilities.hpp"

class ParameterReader
{
private:
    std::map<std::string,std::string> params_;
    //set a value for the key string with value in
    void SetParameter(const std::string &key, const std::string &value);

public:

    ParameterReader() {}
    ~ParameterReader(){}

    //try to read all parameters from file
    bool readParameters(const std::string& filename);
    //check if parameter is already defined
    inline bool IsDefined(const std::string& key) const;
    //get value of key
    template<typename Type>
    inline void GetParameter(const std::string& key, Type &value) const;
    //try to read particle file
    bool readParticleFile(real*& masses,real4*& positions,real4*& velocities, const std::string& filename, uint& N_particles);



};

inline bool ParameterReader::IsDefined(const std::string& key) const
{
    std::map<std::string,std::string>::const_iterator it=params_.find(key),end_it=params_.end();
    return(!(it==end_it));
}

template<typename Type>
inline void ParameterReader::GetParameter(const std::string& key, Type &value) const
{
    std::map<std::string,std::string>::const_iterator it=params_.find(key);
    std::string val = it->second;
    std::istringstream istr(val);
    Type returnVal;
    istr >> returnVal;
    value = returnVal;
}

#endif //ParameterReader_HPP_
